package main

import (
	"context"
	"github.com/segmentio/kafka-go"
)

func main1() {

	// Define the Kafka topic and address
	topic := "opreationlogs"
	address := []string{"10.0.12.38:9092", "10.0.12.39:9092", "10.0.12.40:9092"}

	// Create a new Kafka writer using the specified topic and address
	writer := kafka.NewWriter(kafka.WriterConfig{
		Topic:   topic,
		Brokers: address,
	})

	// Write the message to the Kafka topic
	/**
	 * 登录账号 | 登录账号ID | 操作账号 | 操作账号ID | 操作平台 | 服务名称 | 服务名称别名 | 操作分类 | 操作对象 | 操作时间 | 登录IP | 操作结果 | 失败原因 | 日志等级 | 日志类型           |操作描述
	 * zhangsan| 0ea52fa2 |zhangsan | 0ea52fa2 |   omc  | 角色管理 |    role    | 创建角色 | 名称+ID |2022-03-21|8.8.8.8|成功    |         |普通    |application-operate| 请求json
	 * gaozizhong   3c77c1bbbfca11ec9e660cda411d7aa5
	 */
	err := writer.WriteMessages(context.Background(), kafka.Message{
		//Value: []byte("gaozizhong|3c77c1bbbfca11ec9e660cda411d7aa5|gaozizhong|3c77c1bbbfca11ec9e660cda411d7aa5|omc" +
		//	"|监控平台|unitrap|新建trap|名称+ID|2022-03-21 11:30:05|8.8.8.8|成功|-|普通|application-operate|请求json"),
		Value: []byte("gaozizhong|3c77c1bbbfca11ec9e660cda411d7aa5|gaozizhong|3c77c1bbbfca11ec9e660cda411d7aa5|omc|监控平台|unitrap|新建trap|名称+ID|2022-03-21||成功||普通|application-operate|请求json"),
	})

	// Check for any errors
	if err != nil {
		panic("could not write message " + err.Error())
	}

	// Close the Kafka writer
	err = writer.Close()
	if err != nil {
		panic("could not close writer " + err.Error())
	}
}
